import { createStore } from 'vuex'

export default createStore({
  state: {
    token:sessionStorage.getItem("token"),
    user:JSON.parse(sessionStorage.getItem("user"))
  },
  mutations: {
    SET_TOKEN:(state,token) => {
      state.token = token
      sessionStorage.setItem("token",token)
    },
    GET_TOKEN:(state)=>{
      return state.token
    },
    SET_USER:(state,user)=>{
      state.user = user
      sessionStorage.setItem("user",JSON.stringify(user))
    },
    GET_USER:(state) => {
      return state.user
    },
    CLEAR_TOKEN:(state)=>{
      state.token = ""
      sessionStorage.clear()
    }
  },
  actions: {
  },
  modules: {
  },
  getters: {
    token:state => state.token,
    user:state => state.user
  }
})
